package com.jnu.weather.job;

import com.jnu.weather.domain.WeatherResponse;
import com.jnu.weather.po.City;
import com.jnu.weather.service.CityService;
import com.jnu.weather.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduledTaskJob {
    @Autowired
    WeatherService weatherService;
    @Autowired
    CityService cityService;
    /**
     * 每隔?拉取天气数据缓存到Redis
     */
    @Scheduled(cron="0/30 * * * * ?")
    public void cacheWeatherData(){
        List<City> cityList=cityService.findAllCity();
        for(City city:cityList){
            weatherService.cacheWeatherData(city.getCityid(),city.getCity());
        }
    }
}
